/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using DaveSexton.DocProject.Configuration;
using DaveSexton.DocProject.Sandcastle.Configuration;
using DaveSexton.DocProject.Sandcastle.TopicManagement;
using System.IO;
using System.ComponentModel;
using System.Windows.Forms.Design;

namespace DaveSexton.DocProject.Sandcastle
{
	internal sealed class TopicManagementToolBarCommand : ToolBarCommand
	{
		#region Public Properties
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1802:UseLiteralsWhereAppropriate")]
		public static readonly string DefaultName = "TopicManagement";

		public override string Name
		{
			get { return DefaultName; }
		}

		public override string Tooltip
		{
			get
			{
				return Resources.Text.TopicExplorerCommandTooltip;
			}
		}

		public override bool UseOfficeBitmapResourceId
		{
			get { return false; }
		}

		public override System.Drawing.Image Image
		{
			get
			{
				return Resources.Images.TopicManagement_Button;
			}
		}

		public override System.Drawing.Color ImageTransparencyKey
		{
			get
			{
				return System.Drawing.Color.Fuchsia;
			}
		}

		public override vsCommandStatus Status
		{
			get
			{
				IDocProject project = DocProjectEnvironment.SelectedProject;

				if (project != null && typeof(SandcastleBuildEngineProvider).IsAssignableFrom(project.Provider.GetType()))
					return vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
				else
					return vsCommandStatus.vsCommandStatusSupported;
			}
		}
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="TopicManagementToolBarCommand" /> class.
		/// </summary>
		public TopicManagementToolBarCommand()
		{
		}
		#endregion

		#region Methods
		public override string GetStatusText(object status)
		{
			return Resources.Text.TopicExplorerCommandText;
		}

		public override object Execute(object option, object argument)
		{
			if (DocProjectEnvironment.RunningInVisualStudio)
			{
				TopicExplorer window = (TopicExplorer)
						DocProjectEnvironment.ToolWindows[TopicExplorer.ToolWindowGuid];

				window.Visible = true;

				return null;
			}
			else
			{
				IDocProject project = DocProjectEnvironment.SelectedProject;

				if (project == null)
					return null;

				SandcastleProjectOptions options = project.Options as SandcastleProjectOptions;

				if (options == null)
					return null;

				options.ShowPropertyDialog("TopicManagement", null);

				return options.TopicManagement;
			}
		}
		#endregion
	}
}